import os
from django.core.management.base import NoArgsCommand
from django.conf import settings
from core.utils import *
from core.models import *

DATA_DIR = os.path.abspath(os.path.join(settings.PROJECT_DIR,'data','chicago'))

verbose = True
encoding='iso-8859-1'

class Command(NoArgsCommand):

    help = 'Import the shp files into the Boundary model.'

    def handle_noargs(self, **options):

        """
        Define a queue and process as SHPBoundary sub classes.  SRID is
        required, if it is not available in layer.srs.srid then you can make
        intelligent guesses by looking at the SRS header (layer.srs) and proj4
        (layer.srs.proj4)  definitions and searching
        http://spatialreference.org/.
        """
        queue = (
            # ('filepath', srid, Reader Class, Boundary Class, 'boundary type',
            #  'district key')
            ('data/newyork/nycg.shp',2263,NYSHPReader,StateBoundary,
             'cng','CongDist'),
            ('data/newyork/nyad.shp',2263,NYSHPReader,StateBoundary,
             'hou','AssemDist'),
            ('data/newyork/nycc.shp',2263,NYSHPReader,NYCityBoundary,
             'wrd','CounDist'),
            ('data/newyork/nyss.shp',2263,NYSHPReader,StateBoundary,
             'sen','StSenDist'),
            #('data/bayarea/elect_stsenate_dists.shp',2227,
            # SFBaySHPReader, 'sen'),
            #('data/bayarea/elect_stasmbly_dists.shp',2227,
            # SFBaySHPReader,'hou'),
            #('data/bayarea/elect_precincts.shp',2227,
            # SFBaySHPReader,'wrd'),
            #('data/bayarea/elect_congress_dists.shp',2227,
            # SFBaySHPReader,'cng'),
        )

        for file, srid, reader_cls, boundary_cls, bnd_type, district_key  in queue:
            print '>> Importing %s' % file
            import_shp(reader_cls(file, srid, bnd_type, district_key, boundary_cls))

